package com.edu.app.mapper.core;

import com.edu.app.bean.core.SysOpty;
import com.edu.app.model.OptyModel;
import com.edu.app.util.AppBaseMapper;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface SysOptyMapper extends AppBaseMapper<SysOpty> {
    @Select("select t1.id,t1.amount,t1.name,t1.description," +
            "t1.customer_id,t3.name as customer_name,t1.user_id,t2.nickname as user_name,t1.stage_id,t4.value as stage " +
            "from s_opty t1 inner join s_user t2 on t1.user_id = t2.id " +
            "inner join s_customer t3 on t1.customer_id = t3.id " +
            "inner join s_list_of_value t4 on t1.stage_id = t4.id where t1.user_id = #{user_id}")
    @Results({
            @Result(property = "id",  column = "id"),
            @Result(property = "amount", column = "amount"),
            @Result(property = "name", column = "name"),
            @Result(property = "description", column = "description"),
            @Result(property = "customer_id", column = "customer_id"),
            @Result(property = "customer_name", column = "customer_name"),
            @Result(property = "user_id", column = "user_id"),
            @Result(property = "user_name", column = "user_name"),
            @Result(property = "stage_id", column = "stage_id"),
            @Result(property = "stage", column = "stage")

    })
    List<OptyModel> getOptyModel(Integer user_id);
}
